package dao;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

import dao.mapMysql.MapDAOFactory;
import dao.mysql.MySqlDAOFactory;
import enums.DBMS;

/**
 *	Abstract class DAO Factory. </br>
 *  Create the Data Access Object Layer by according Factory pattern design
 * 	Default: MapDAOFactory
 */
public abstract class DAOFactory {


	private static final String String = null;
	private static String PROPERTIES_FILE_PATH = "config/database.props";
	private static String DBMS = "MapMySQL";
	
	public abstract IValueDAO getValueDAO();
	public abstract IEventDAO getEventDAO();
    public abstract IEventTypeDAO getEventTypeDAO();
    public abstract ISubjectDAO getUserDAO();
    public abstract IObjectDAO getItemDAO();
    public abstract ITestConnection getTestConnection();

    public static DAOFactory getDAOFactory()
    {
    	Properties prop = new Properties();
    	
    	try {
    		prop.load(new FileInputStream(PROPERTIES_FILE_PATH));
    		DBMS = prop.getProperty("DAO") != null ? prop.getProperty("DAO") : "MapMySQL";
    	} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
    	
    	return getDAOFactory(DBMS);
    }
    
    public static DAOFactory getDAOFactory(String dbms) {
    	  
    	    switch (dbms) {
    	      case "MySQL": 
    	          return new MySqlDAOFactory();
    	      case "MapMySQL": 
    	          return new MapDAOFactory();      
    	      default: 
    	          return new MapDAOFactory();
    	    }
    	  }    

}
